package org.springframework.core.io;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * @Name ClassPathResource
 * @Description: ClassPath下的资源 [实现] 类
 * @Version v1.0.0
 * @Author: lichao
 * @Date: 2024-03-15 15:14:09
 **/
public class ClassPathResource implements Resource {
    private final String path;

    public ClassPathResource(String path) {
        this.path = path;
    }

    @Override
    public InputStream getInputStream() throws IOException {
        InputStream is = this.getClass().getClassLoader().getResourceAsStream(this.path);
        if(is == null)
            throw new FileNotFoundException(this.path + " 不能被打开，因为它不存在");
        return is;
    }
}

